import json
import os

count = 0
msg = ""
path = "\\\\192.168.30.177\\样例数据\\cnipapatent\\cnipapatent_cover_20181029"
with open("./jsoncover.txt", "w", encoding="utf-8") as f:
    for path, dirNames, fileNames in os.walk(path, topdown=True):
        # 获取当前目录的所有文件
        for fileName in fileNames:
            if fileName.endswith(".jpg"):
                count += 1
                line = fileName.replace(".jpg", "")
                path = "/smartlib/cnipapatent/{}/{}/{}.jpg".format(line[:3].lower(), line[3:7].lower(), line.lower())
                # jsonmsg = json.dumps({"pub_no": line, "cover": path})
                msg += line + "\n"
                if count % 30000 == 1:
                    f.write(msg)
                    msg = ""
                    print(count)
    if msg:
        f.write(msg)
    print("Total %d" % count)

